package com.guan.poi.tmp;

import com.guan.poi.xml.config.PoiStyleConfig;
import lombok.Getter;
import lombok.Setter;

/**
 * 临时对象
 */
@Getter
@Setter
public class Region {
    private int firstRow;
    private int lastRow;
    private int firstCol;
    private int lastCol;
    private String value;
    private PoiStyleConfig style;

    public Region(int firstRow, int lastRow, int firstCol, int lastCol, PoiStyleConfig style) {
        this.firstRow = firstRow;
        this.lastRow = lastRow;
        this.firstCol = firstCol;
        this.lastCol = lastCol;
        this.style = style;
    }


    public void merge(int firstRow, int lastRow, int firstCol, int lastCol, PoiStyleConfig style) {
        if(this.firstRow>firstRow) {
            this.firstRow = firstRow;
            this.style.setBorderTop(style.getBorderTop());
        }
        if(this.lastRow<lastRow) {
            this.lastRow = lastRow;
            this.style.setBorderBottom(style.getBorderBottom());
        }
        if(this.firstCol>firstCol) {
            this.firstCol = firstCol;
            this.style.setBorderLeft(style.getBorderLeft());
        }
        if(this.lastCol<lastCol) {
            this.lastCol = lastCol;
            this.style.setBorderRight(style.getBorderRight());
        }
    }

    public void setLastRow(int lastRow, PoiStyleConfig style) {
        if(this.lastRow<lastRow) {
            this.lastRow = lastRow;
            this.style.setBorderBottom(style.getBorderBottom());
        }
    }
}
